package com.xyulu.config.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author Xyulu
 * @Date 2021/1/30 22:53
 * @Version 1.0
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload.img}")
    private String uploadImgPath;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

    }

    /**
     * 添加一些虚拟路径的映射
     * 静态资源路径和上传文件的路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * @Description: 对文件的路径进行配置, 创建一个虚拟路径/uploadImg/** ，即只要在< img src="/uploadImg/picName.jpg" />便可以直接引用图片
         *这是图片的物理路径  "file:/+本地图片的地址"
         */
        registry.addResourceHandler("/uploadImg/**").addResourceLocations("file:/"+uploadImgPath);
    }
}
